package vn.edu.ctu.cit.se.android.karfinder;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class KarFinderActivity extends TabActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		buildTabs();
		checkDatabaseEmpty(KarFinderActivity.this);
	}
	
	/**
	 * @author Val
	 * 
	 */
	private void buildTabs() {
		Resources res = getResources();
		TabHost tabHost = getTabHost();
		TabHost.TabSpec spec;
		Intent intent;
		
		Class<?>[] classNames = { SearchActivity.class,
								  SongActivity.class,
								  FavoriteActivity.class,
								  PlaylistActivity.class,
								  HelpActivity.class };
		
		String[] specNames = res.getStringArray(R.array.tab_spec_names);
		String[] indicatorNames = res.getStringArray(R.array.tab_indicator_names);
		int[] tabIcons = { R.drawable.ic_tab_search,
						   R.drawable.ic_tab_song, 
						   R.drawable.ic_tab_favorite,
						   R.drawable.ic_tab_playlist,
						   R.drawable.ic_tab_help };
		
		for (int i = 0; i < specNames.length; i++) {
			intent = new Intent().setClass(this, classNames[i]);
			spec = tabHost.newTabSpec(specNames[i])
						  .setIndicator(indicatorNames[i], res.getDrawable(tabIcons[i]))
						  .setContent(intent);
			tabHost.addTab(spec);
		}
	}
	
	/**
	 * @author Val
	 * 
	 */
	private void checkDatabaseEmpty(Context context) {
		SongUpdater songUpdater = new SongUpdater(context);
		songUpdater.updateFromFile();
	}
}